home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qlib205.zip / QLIB.ZIP / TEST / PACK / PACK.ASM < prev    next >
Assembly Source File  |  1997-02-12  |  2KB  |  100 lines

  1. ;this example uses pack_open()
  2.  
  3. include qlib.inc
  4. include dos.inc
  5. include string.inc
  6. include stdio.inc
  7. include process.inc
  8.  
  9. include data_hdr.asm
  10.  
  11. .data
  12.   buf db 1024 dup (0)
  13.   buf2 db 1024 dup (0)
  14.   h dw ?
  15.   siz dd ?
  16.   ph dw ?  ;pack file handle
  17. .code
  18. main proc
  19.   callp pack_init,256,2
  20.   .if eax==ERROR
  21.     callp printf,"\npack_init() failed!\n"
  22.     callp exit,0
  23.   .endif
  24.   callp pack_open,"data.000"
  25.   .if eax==ERROR
  26.     callp printf,"\npack_open() failed!\n"
  27.     callp exit,0
  28.   .endif
  29.   mov ph,ax
  30.   callp open,"file1",0
  31.   mov h,ax
  32.   .if eax==ERROR
  33.     callp printf,"\nopen(file1) failed!\n"
  34.     callp exit,0
  35.   .endif
  36.   callp lseek,h,0,SEEK_SET
  37.   callp lseek,h,1,SEEK_CUR  ;test lseeking with a pack file (skip the 1st byte)
  38.   callp filelength,h
  39.   mov siz,eax
  40.   callp read,h,offset buf,132     ;filesiz=132 but we have lseek one byte over
  41.                                    ;what will happen? pack.asm will cut it off so we
  42.                                    ;don't start reading the next file.
  43.   .if eax!=131
  44.     callp printf,"error read eax=%d\n",eax
  45.   .endif
  46.   callp read,h,offset buf,100     ;try to read more : it will fail
  47.   .if eax
  48.     callp printf,"Error #2\n"
  49.   .endif
  50.   callp printf,offset buf
  51.   callp eof,h
  52.   .if eax
  53.     callp printf,"\nEOF=true\n"
  54.   .else
  55.     callp printf,"\nEOF=false (bug?)\n"
  56.   .endif
  57.   callp printf,"\n File length of FILE1=%d\n\n",siz
  58.   callp close,h
  59.  
  60.   callp pack_close,ph       ;you can open many pack's if you want
  61.   .if eax==ERROR
  62.     callp printf,"\n pack_close() failed!\n"
  63.     callp exit,0
  64.   .endif
  65.   callp pack_open_hdr,"data.001",offset the_header
  66.   .if eax==ERROR
  67.     callp printf,"\n pack_open_hdr() failed!\n"
  68.     callp exit,0
  69.   .endif
  70.   mov ph,ax
  71.  
  72.   callp open,"file2",0  ;this will fail if pack_close() above is unremed
  73.   mov h,ax
  74.   .if ax==ERROR
  75.     callp printf,"\nopen(file2) failed!\n"
  76.     callp exit,0
  77.   .endif
  78.   callp read,h,offset buf2,300
  79.   callp close,h
  80.   callp printf,offset buf2
  81. ;some xtra lseek tests
  82.   callp lseek,h,0,SEEK_END
  83.   callp printf," Pos 1=%i",eax
  84.   callp lseek,h,303,SEEK_END
  85.   callp printf," Pos 2=%i",eax
  86.   callp lseek,h,304,SEEK_END
  87.   callp printf," Pos 3=%i",eax
  88.   callp lseek,h,-303,SEEK_CUR
  89.   callp printf," Pos 4=%i",eax
  90.   callp lseek,h,303,SEEK_SET
  91.   callp printf," Pos 5=%i",eax
  92.   callp lseek,h,-309,SEEK_CUR
  93.   callp printf," Pos 6=%i",eax
  94.   callp lseek,h,1,SEEK_END
  95.   callp printf," Pos 7=%i",eax
  96.   ret
  97. main endp
  98.  
  99. end
  100.